package com.deyuanyun.pic.ctrl.validatefun;

import com.deyuanyun.pic.common.spring.SpringAppliction;
import com.deyuanyun.pic.common.validator.vinterface.ValidateInterface;
import com.deyuanyun.pic.ctrl.annotation.DbTable;
import com.deyuanyun.pic.ctrl.domain.EqptCptestStation;
import com.deyuanyun.pic.ctrl.service.EQPTBaseService;
import org.apache.commons.beanutils.BeanUtils;

import java.lang.reflect.Field;

/**
 * 模块描述
 *
 * @author scalpel.王敏
 * @version [v1.0] 创建时间（2016/11/23）
 * @see // 引用的类
 * Method List:
 * 1.----------------
 * 2.----------------
 * History:
 */
public class TestStationVali implements ValidateInterface {
    @Override
    public <T, E, C> boolean apply(T t, E e, C c) throws NoSuchFieldException {
        Object obj= c;
        Field f=(Field) e;
        String val= (String) t;
        try{
            EQPTBaseService service= SpringAppliction.getBean(EQPTBaseService.class);
            Object device=service.queryObjectByCustomNumber(EqptCptestStation.class,val);
            if(device != null)
            {
                String id= BeanUtils.getSimpleProperty(device,"id");
                BeanUtils.setProperty(c,f.getName(),id);
                return  true;
            }

        }catch (Exception e1)
        {
            e1.getStackTrace();
        }


        return false;
    }

    @Override
    public String getName() {
        return null;
    }
}
